ig.module(

    'game.entities.kami'

).requires(
           
    'impact.entity',
    'game.entities.particle'    

).defines(function(){
    
    EntityKami = ig.Entity.extend({
        size: {
            x: 4,
            y: 6
        },
        offset: {
            x: 2,
            y: 2
        },
        maxVel: {
            x: 200,
            y: 200
        },
        type: ig.Entity.TYPE.B,
        checkAgainst: ig.Entity.TYPE.A,
        collides: ig.Entity.COLLIDES.PASSIVE,
        health: 20,
        
        sawPlayer: false,
        
        seeDistance: 150,
        
        maxJump: 300,
        
        animSheet: new ig.AnimationSheet('media/sprites/kami.png', 8, 8),
        
        init: function(x,y,settings){
            
            this.parent( x,y,settings );
            
            this.addAnim('idle', 1, [0]);
            
        },
        
        update: function(){
            var pl = ig.game.player;
            
            if( this.distanceTo( pl ) < this.seeDistance ){                
                this.sawPlayer = true;                
            }
            if( this.sawPlayer ){
                var xdir = this.pos.x - pl.pos.x < 0 ? 1 : -1;
                
                if( this.standing ){
                    this.vel.y = - (Math.random() * this.maxJump)/3;
                    this.vel.x =  xdir * 50
                }
            }
            
            this.parent();            
        },
        
        kill: function(){
            var gibs = ig.ua.mobile ? 5 : 20;
            for (var i = 0; i < gibs; i++) {
                ig.game.spawnEntity(EntityKamiGib, this.pos.x, this.pos.y);
            }
            this.parent();
        }        
    });
    
    EntityKamiGib = EntityParticle.extend({
        lifetime: 3,
        fadetime: 6,
        friction: {
            x: 0,
            y: 0
        },
        vel: {
            x: 60,
            y: 150
        },
        animSheet: new ig.AnimationSheet('media/sprites/blob-gibs.png', 4, 4),
        init: function (x, y, settings) {
            this.addAnim('idle', 0.1, [0, 1, 2]);
            this.parent(x, y, settings);
        }
    });
    
    
});